/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package entities;

import java.io.PrintWriter;
import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 *
 * @author valiadam
 */
@Entity
@Table(name = "conversation", catalog = "ltschat", schema = "")
@NamedQueries({@NamedQuery(name = "Conversation.findAll", query = "SELECT c FROM Conversation c"), @NamedQuery(name = "Conversation.findById", query = "SELECT c FROM Conversation c WHERE c.id = :id"), @NamedQuery(name = "Conversation.findByName", query = "SELECT c FROM Conversation c WHERE c.name = :name"), @NamedQuery(name = "Conversation.findByPrivate1", query = "SELECT c FROM Conversation c WHERE c.private1 = :private1")})
public class Conversation implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "id", nullable = false)
    private Integer id;
    @Basic(optional = false)
    @Column(name = "name", nullable = false, length = 60)
    private String name;
    @Lob
    @Column(name = "details", length = 65535)
    private String details;
    @Column(name = "private")
    private Boolean private1;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "conversationid")
    private Collection<Message> messageCollection;
    @OneToMany(mappedBy = "conversationid")
    private Collection<Loggedin> loggedinCollection;

    public Conversation() {
    }

    public Conversation(Integer id) {
        this.id = id;
    }

    public Conversation(Integer id, String name) {
        this.id = id;
        this.name = name;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDetails() {
        return details;
    }

    public void setDetails(String details) {
        this.details = details;
    }

    public Boolean getPrivate1() {
        return private1;
    }

    public void setPrivate1(Boolean private1) {
        this.private1 = private1;
    }

    public Collection<Message> getMessageCollection() {
        return messageCollection;
    }

    public void setMessageCollection(Collection<Message> messageCollection) {
        this.messageCollection = messageCollection;
    }

    public Collection<Loggedin> getLoggedinCollection() {
        return loggedinCollection;
    }

    public void setLoggedinCollection(Collection<Loggedin> loggedinCollection) {
        this.loggedinCollection = loggedinCollection;
    }

    public void printMessages (PrintWriter out)
    {
        for (Message m : messageCollection)
        {
            if (m != null)
            {
                out.println(m.getDisplayableVersion());
            }
        }
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Conversation)) {
            return false;
        }
        Conversation other = (Conversation) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entities.Conversation[id=" + id + "]";
    }

}
